package kr.couponplay.android;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import kr.couponplay.android.domain.DealDao;
import kr.couponplay.android.domain.DealList;

public class AppContext {
	public static final String TAG = "COUPONPLAY";
	public static final String PREFERENCE_NAME = "couponplay.properties";
	
	public static DealDao dao = new DealDao();
	
	public static ServiceInfo serviceInfo = new ServiceInfo();
	
	/** use : get deal from server */
	public static int page = 1;
	public static String query = "";
	public static SortingType sortingType;
	public static int itemCountInPage = 40;
	public static int mainMenuId;
	public static int subMenuId;
	public static String searchType;
	
	/** use : main activity **/
	public static DealList dealList;

	/** use : category activity **/
	public static ArrayList<Category> categoryGroups;
	public static ArrayList<ArrayList<ArrayList<Category>>> categoryChildren;

	public static String sid;
	
	public static void clear() {
		serviceInfo = null;
		clearSearch();
		dealList = null;
		categoryGroups = null;
		categoryGroups = null;
	}
	
	public static void clearSearch() {
		page = 1;
		query = "";
		sortingType = null;
		mainMenuId = 0;
		subMenuId = 0;
		searchType = null;
	}
	
	public static DealList getMainDealList() {
		return serviceInfo.getMainDealList();
	}
	
	public static int getTotalDealCount() {
		return serviceInfo.getTotalDealCount();
	}
	
	public static Date getLastUpdatedAt() {
		return serviceInfo.getLastUpdatedAt();
	}
	
	public static List<String> getPopularQueries() {
		return serviceInfo.getPopularQueries();
	}
	
	public static Category getCategory() {
		return serviceInfo.getCategory();
	}

	public static void setServiceInfo(ServiceInfo serviceInfo) {
		if (serviceInfo == null) {
			serviceInfo = new ServiceInfo();
		}
		AppContext.serviceInfo = serviceInfo;
	}

	public static int getPage() {
		if (page < 1) {
			return 1;
		}
		return page;
	}

	public static String getSortingType() {
		if (sortingType == null) {
			return SortingType.HIT.name();
		}
		return sortingType.name();
	}
}
